///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_MAT_CUMULATIVE_H_
#define _BUOLA_MAT_CUMULATIVE_H_

#include <buola/mat/cexpr.h>
#include <buola/mat/detail/ccumulativeop.h>
#include <buola/mat/detail/cdiffop.h>

#include <buola/functors/transform/binary.h>

namespace buola { namespace mat {

template<typename tLH>
detail::CCumulativeOp<const tLH&,fn::AAdd,fn::ASubtract,detail::NCumulativeAll>
cumsum(const CExpr<tLH> &pLH)
{
    return {pLH.Derived(),{},{}};
}
    
template<typename tLH>
detail::CCumulativeOp<const tLH&,fn::AAdd,fn::ASubtract,detail::NCumulativeRows>
cumsum(const detail::CRowwiseOp<tLH> &pLH)
{
    return {pLH.Sub(),{},{}};
}
    
template<typename tLH>
detail::CCumulativeOp<const tLH&,fn::AAdd,fn::ASubtract,detail::NCumulativeCols>
cumsum(const detail::CColwiseOp<tLH> &pLH)
{
    return {pLH.Sub(),{},{}};
}
    
template<typename tLH>
detail::CCumulativeOp<const tLH&,fn::AMultiply,fn::ADivide,detail::NCumulativeAll>
cumprod(const CExpr<tLH> &pLH)
{
    return {pLH.Derived(),{},{}};
}
    
template<typename tLH>
detail::CCumulativeOp<const tLH&,fn::AMultiply,fn::ADivide,detail::NCumulativeRows>
cumprod(const detail::CRowwiseOp<tLH> &pLH)
{
    return {pLH.Sub(),{},{}};
}
    
template<typename tLH>
detail::CCumulativeOp<const tLH&,fn::AMultiply,fn::ADivide,detail::NCumulativeCols>
cumprod(const detail::CColwiseOp<tLH> &pLH)
{
    return {pLH.Sub(),{},{}};
}

template<typename tLH>
OEnableIf<detail::QRowVector<tLH>,detail::CDiffOp<const tLH&,fn::ASubtract,true>>
diff(const CExpr<tLH> &pLH)
{
    return {pLH.Derived(),{}};
}
    
template<typename tLH>
OEnableIf<detail::QColVector<tLH>,detail::CDiffOp<const tLH&,fn::ASubtract,false>>
diff(const CExpr<tLH> &pLH)
{
    return {pLH.Derived(),{}};
}
    
template<typename tLH>
detail::CDiffOp<const tLH&,fn::ASubtract,true>
diff(const detail::CRowwiseOp<tLH> &pLH)
{
    return {pLH.Sub(),{}};
}
    
template<typename tLH>
detail::CDiffOp<const tLH&,fn::ASubtract,false>
diff(const detail::CColwiseOp<tLH> &pLH)
{
    return {pLH.Sub(),{}};
}
    
/*namespace mat*/ } /*namespace buola*/ }

#endif
